package com.javacoo.xservice.base.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 拦截器基类
 * <p>
 * 说明:
 * </p>
 * <li></li>
 * 
 * @author DuanYong
 * @since 2017年2月7日下午4:13:02
 */
public class BaseInterceptor extends HandlerInterceptorAdapter {
	private BaseInterceptor nextInterceptor;


    public void setNextInterceptor(BaseInterceptor nextInterceptor) {
        this.nextInterceptor = nextInterceptor;
    }
    /**
     * 预处理
     */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		if (nextInterceptor == null) {
			return true;
		}
        if (!nextInterceptor.preHandle(request, response, handler)) {
            return false;
        }
		return true;
	}
    /**
     * 后处理
     */
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		if (nextInterceptor == null) {
		    return;
		}
        nextInterceptor.postHandle(request, response, handler, modelAndView);
	}

    /**
     * 返回处理
     */
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		if (nextInterceptor == null) {
            return;
		}
        nextInterceptor.afterCompletion(request, response, handler, ex);
	}
	/**  
     * 处理异步请求  
     */ 
	@Override
	public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		if (nextInterceptor == null) {
            return;
		}
        nextInterceptor.afterConcurrentHandlingStarted(request, response, handler);
	}
}
